package com.dragon.concurrent.demo.cas;

/**
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/6/2 13:39
 */
public class AtomicDemo {

    public static void main(String[] args) {
        Jack jack = new Jack();
        for (int i = 0; i < 100; i++) {
            new Thread(jack).start();
        }
    }

}

class Jack implements Runnable {
    private volatile int num = 1;
//    private int num = 1;

    @Override
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.print(getNum() + "  ");

    }

    public int getNum() {
        return num++;
    }

}
